<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>手写map</title>
</head>
<body>
    
</body>
<script>
    function map(fn){
        let arr = this || []
        let newArr = []
        for (let i = 0; i < arr.length; i++){
            let res = fn(arr[i], i)
            newArr.push(res)
        }
        return newArr
    }
    let arr = [1,2,3]
    let b = arr.map((item, i) => {
        console.log(item, i)
        return item+1
    })
    console.log(arr, b)
    
</script>
</html>